<!-- 填写发货信息 -->
<div class="deliver-wrap" id="deliver_wrap">
    <a href="javascript:void(0)" class="close" id="deliver_close">X</a>
    <div class="title">
        <h4>填写发货信息</h4>
    </div>
    <div class="cont">
        <div id="warning" class="warning"></div>
        <form action="index.php?app=seller_order&amp;act=shipped&amp;order_id={$order.order_id}" method="post" id="wlform">
            <p style="background: #f1f1f1;margin: 10px 5px 15px 62px;padding:5px 0 5px 10px;font-size: 18px;">
                <input type="checkbox" name="their" {if $orderextm.shipping_name eq '自提'}checked{/if} value="自提" id="their" />
                <label for="their">自提</label>
            </p>
            <table width="100%">
                <tr id="J_shipped_a">
                    <td align="right" width="120" valign="top"> <i>*</i>
                        物流公司：
                    </td>
                    <td>
                        <ul class="seller-order-shipped f-cb">
                        <!--{foreach from=$cfg_shipping_kuaidi name=kuaidi key=key item=kuaidi}-->
                        <li>
                            <input type="radio" name="express" class="express" id="express_type{$smarty.foreach.kuaidi.index}" value="{$key}" {if $orderextm.shipping_name eq $key}checked{/if} />
                            <label for="express_type{$smarty.foreach.kuaidi.index}">{$key}</label>
                        </li>
                        <!--{/foreach}--> </ul>
                    </td>
                </tr>
                <tr id="J_shipped_b">
                    <td align="right"> <i>*</i>
                        物流单号：
                    </td>
                    <td>
                        <input type="text" name="invoice_no" class="txt" value="{$order.invoice_no}" />
                    </td>
                </tr>
                <tr>
                    <td>&nbsp;</td>
                    <td>
                        <input type="submit" value="提交发货信息" class="subbtnhs" />
                    </td>
                </tr>
            </table>
        </form>
    </div>
</div>

<!-- 修改收货地址 -->
<div class="receiving-wrap" id="receiving_wrap">
    <a href="javascript:void(0)" class="close" id="receiving_close">X</a>
    <div class="title">
        <h4>修改收货地址</h4>
    </div>
    <div class="cont">
        <div id="warning2" class="warning"></div>
        <form action="{url app=seller_order&act=edit_address}" method="post" id="receivingform">
            <table width="100%">
                <tr>
                    <td align="right" width="150">
                        <i>*</i>
                        收货人姓名：
                    </td>
                    <td>
                        <input type="text" name="consignee" class="txt" value="{$order.orderextm_info.consignee|escape}" />
                    </td>
                </tr>
                <tr>
                    <td align="right" width="150">
                        <i>*</i>
                        {$lang.region}：
                    </td>
                    <td id="region">
                        <input type="hidden" name="region_id" value="{$order.orderextm_info.region_id}" id="region_id" class="mls_id" />
                        <input type="hidden" name="region_name" value="{$order.orderextm_info.region_name|escape}" class="mls_names" />
                        <!-- {if $order.orderextm_info.region_id} -->
                        <span>{$order.orderextm_info.region_name|escape}</span>
                        <input type="button" value="{$lang.edit}" class="edit_region" />
                        <select style="display:none" onchange="hide_error();">
                            <option>{$lang.select_pls}</option>
                            {html_options options=$regions}
                        </select>
                        <!-- {else} -->
                        <select onchange="hide_error();">
                            <option>{$lang.select_pls}</option>
                            {html_options options=$regions}
                        </select>
                        <!-- {/if} --> <b class="field_message" style="font-weight:normal;"><label class="field_notice"></label></b> 
                    </td>
                </tr>
                <tr>
                    <td align="right">
                        <i>*</i>
                        具体收货地址：
                    </td>
                    <td>
                        <input type="text" name="address" class="txt2" placeholder="不必重复填写地区" value="{$order.orderextm_info.address|escape}" />
                    </td>
                </tr>
                <tr>
                    <td align="right">
                        <i>&nbsp;</i>
                        邮政编码：
                    </td>
                    <td>
                        <input type="text" class="txt" name="zipcode" value="{$order.orderextm_info.zipcode|escape}" maxlength="6" onkeyup="this.value = this.value.replace(/\D/g, '')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/\D/g,''))" />
                    </td>
                </tr>
                <tr>
                    <td align="right">
                        <i>&nbsp;</i>
                        手机号码：
                    </td>
                    <td>
                        <input type="text" class="txt" name="phone_mob" id="phone_mob" placeholder="电话号码、手机号码必须填一项" value="{$order.orderextm_info.phone_mob}" maxlength="11" onkeyup="this.value = this.value.replace(/\D/g, '')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/\D/g,''))" />
                    </td>
                </tr>
                <tr>
                    <td align="right">电话号码：</td>
                    <td>
                        <input type="text" class="text width4 b-radius" name="phone_section" placeholder="区号" value="{$phone_tel.0}" maxlength="4" id="phone_section" onkeyup="this.value = this.value.replace(/\D/g, '')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/\D/g,''))" />
                        -&nbsp;
                        <input type="text" class="text w100 b-radius" name="phone_code" placeholder="电话号码" value="{$phone_tel.1}" id="phone_code" maxlength="8" onkeyup="this.value = this.value.replace(/\D/g, '')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/\D/g,''))" />
                        -&nbsp;
                        <input type="text" class="text width4 b-radius" name="phone_ext" placeholder="分机" value="{$phone_tel.2}" id="phone_ext" maxlength="6" onkeyup="this.value = this.value.replace(/\D/g, '')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/\D/g,''))" />
                    </td>
                </tr>
                <tr>
                    <td>
                        &nbsp;
                        <input type="hidden" value="{$order.order_id}" name="order_id" />
                    </td>
                    <td>
                        <input type="submit" value="修改收货地址" class="subbtnhs" />
                    </td>
                </tr>
            </table>
        </form>
    </div>
</div>

<script type="text/javascript" src="{lib file=jquery.plugins/additional-methods.js}" charset="utf-8"></script>
<script type="text/javascript">
var controller ='{$orderextm.shipping_name}' ? false : true;
$.validator.addMethod("check_type", function(value, element) {
    var go=true;
    if(controller){
        if(element.name === 'express'){
            if($('input[name="express"]:checked').length<1){
                go=false;
            }
        }else{
            if (value.length < 1) {
                go = false;
            }
        }
    }
    return go;
});

$.validator.addMethod('checkZipcode',function(value){
     var region_id = $('#region_id').val();
     return checkPostcode(value,region_id);
});

$.validator.addMethod('checkContact', function(value) {
    var v0 = $('#phone_section').val(),
        v1 = $('#phone_code').val(),
        v2 = $('#phone_ext').val();
    var go = true;
    if (value == '') {
        if (v0 == '' && v1 == '' && v2 == '') {
            go = false;
        }
    }
    return go;
}, '手机号码和电话号码不能同时为空');

$.validator.addMethod('isAreaEmpty', function() {
    var v0 = $('#phone_section').val(),
        v1 = $('#phone_code').val();
    return checkArea(v0, v1);
}, '区号不正确');

$.validator.addMethod('isTelEmpty', function() {
    var v0 = $('#phone_section').val(),
        v1 = $('#phone_code').val();
    return checkTel(v0, v1);
}, '电话号码不正确');

function checkPostcode(val, region_id) {
    if (val == '' || region_id == '3409') {
        return true; //如果是海外，邮政编码可以为空
    } else {
        var _reg = /^\d{6}$/;
        return _reg.test(val);
    }
}

function checkArea(v0, v1) {
    var phone_mob = $('#phone_mob').val();
    var go = true;
    var r0 = /^\d{3,4}$/;
    if (phone_mob != '') {
        if(v1 == ''){
            if(v0 == ''){
                go = true;
            }else if(v0 != '' && r0.test(v0)){
                go = true;
            }else{
                go=false;
            }
        }else{
            if(r0.test(v0)){
                go=true;
            }else{
                go=false;
            }
        }
    }else{
      if (r0.test(v0)) {
          go = true;
      } else {
          go = false;
      }
    }
    return go;
}

function checkTel(v0, v1) {
    var phone_mob = $('#phone_mob').val();
    var go = true;
    var r1 = /^\d{7,8}$/;
    if (phone_mob != '') {
        if(v0 == ''){
            if(v1 == ''){
                go = true;
            }else if(v1 != '' && r1.test(v1)){
                go = true;
            }else{
                go=false;
            }
        }else{
            if(r1.test(v1)){
                go=true;
            }else{
                go=false;
            }
        }
    }else{
      if (r1.test(v1)) {
          go = true;
      } else {
          go = false;
      }
    }
    return go;
}

$(function() {
    regionInit("region");

    var deliver_btn=$('#deliver_btn'),
    address_btn=$('#address_btn'),
    receiving_close=$('#receiving_close'),
    deliver_close=$('#deliver_close');

    deliver_btn.bind('click',function(){
            wl.showMod('#deliver_wrap');
    });
    deliver_close.bind('click',function(){
            wl.hiddenMod('#deliver_wrap');
    });

    address_btn.bind('click',function(){
            wl.showMod('#receiving_wrap');
    });
    receiving_close.bind('click',function(){
            wl.hiddenMod('#receiving_wrap');
    });

    $('#wlform').validate({
        errorLabelContainer: $('#warning'),
        rules: {
            express:{
                check_type: true
            },
            invoice_no:{
                check_type: true
            }
        },
        messages: {
            express:{
                check_type:'请选择物流公司'
            },
            invoice_no:{
                check_type:'物流单号不能为空'
            }
        }
    });

    $('#receivingform').validate({
        errorLabelContainer: $('#warning2'),
        rules: {
            consignee:{
                required: true
            },
            region_id : {
                countSelect : true
            },
            address:{
                required: true
            },
            zipcode:{
                checkZipcode : true
            },
            phone_mob:{
                checkContact : true,
                isMobile : true
            },
            phone_section :{
                isAreaEmpty : true
            },
            phone_code : {
                isTelEmpty : true
            }
        },
        messages: {
            consignee:{
                required:'收货人姓名不能为空'
            },
            address:{
                required:'收货地址不能为空'
            },
            zipcode:{
                checkZipcode:'邮政编码错误'
            }
        }
    });

    /*弹窗内操作A*/
    $('#their').bind('click', function() {
        $('#warning').empty().hide();
        if ($(this).attr('checked')) {
            controller = false;
            $('#J_shipped_a').hide();
            $('#J_shipped_b').hide();
        } else {
            controller = true;
            $('#J_shipped_a').show();
            $('#J_shipped_b').show();
        }
    });


});
</script>